package apis.amapv2.com.io.inoutstream;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

import apis.amapv2.com.io.R;
import apis.amapv2.com.io.activity.FileInputStream1Activity;
import apis.amapv2.com.io.activity.FileInputStream2Activity;
import apis.amapv2.com.io.activity.FileOutputStream1Activity;
import apis.amapv2.com.io.activity.FileOutputStream2Activity;
import apis.amapv2.com.io.addpter.ItemAdapter;
import apis.amapv2.com.io.bean.ItemObject;

public class InOutStremActivity extends AppCompatActivity {

    private ListView mLv;
    private Context mContext;
    private List<ItemObject> mData = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_in_out);

        initParamsAndValues();
        initView();
    }

    private void initParamsAndValues() {
        mContext = this;

        mData.add(new ItemObject("一个一个读取字节", FileInputStream1Activity.class));
        mData.add(new ItemObject("read()方法返回的是一个字节，为什么会用int接受？",FileInputStream2Activity.class));
        mData.add(new ItemObject("一个字节一个字节的写入",FileOutputStream1Activity.class));
        mData.add(new ItemObject("通过FileOutPutStream追加数据",FileOutputStream2Activity.class));
    }

    private void initView() {
        mLv = findViewById(R.id.lv);
        mLv.setAdapter(new ItemAdapter(mContext,mData));
        mLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(new Intent(mContext,mData.get(position).getClazz()));
            }
        });
    }
}
